package com.my.wemedia.controller.v1;

import com.my.model.admin.dtos.NewsAuditDto;
import com.my.model.admin.dtos.WeMediaDto;
import com.my.model.common.dtos.ResponseResult;
import com.my.model.wemedia.dtos.WmNewsDto;
import com.my.model.wemedia.dtos.WmNewsPageReqDto;
import com.my.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 获取文章内容列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult getContentList(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findContentList(dto);
    }

    /**
     * 文章上架或下架
     * @param map
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult<String> downOrUp(@RequestBody Map<String,Integer> map){
        return wmNewsService.downOrUp((Integer) map.get("id"),(Integer) map.get("enable"));
    }

    /**
     * 修改或提交文章
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) throws Exception {
        return wmNewsService.submitNews(dto);
    }

    /**
     * 修改文章接口
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult modifyArticleApi(@PathVariable Integer id) {
        return wmNewsService.modifyArticleApi(id);
    }

    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteArticle(@PathVariable Integer id){
        return wmNewsService.deleteArticle(id);
    }

    /**
     * 管理端媒体审核
     * @param weMediaDto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult NewsAudit(@RequestBody WeMediaDto weMediaDto) {
        return wmNewsService.auditWmNews(weMediaDto);
    }

    /**
     * 管理端查看文章信息
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult getOneNews(@PathVariable Integer id) {
        return wmNewsService.getOneNews(id);
    }

    /**
     * 人工审核通过
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult auditPass(@RequestBody NewsAuditDto dto) {
        return wmNewsService.auditPass(dto);
    }

    /**
     * 人工审核不通过
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult auditFail(@RequestBody NewsAuditDto dto) {
        return wmNewsService.auditFail(dto);
    }
}
